import logging
from cgitb import handler

#默认情况下，logging 输出warning及以上的日志
#指定输出级别，输出info及以上级别的日志
logging.basicConfig(level=logging.INFO)

logging.debug("this is debug message")
logging.info("this is info message")
logging.warning("this is warning message")
logging.error("this is error message")
logging.critical("this is critical message")

logger = logging.getLogger("__name__")
#给logger对象设置自己的日志，级别
handler = logging.FileHandler(filename="mylog.log")

formatter = logging.Formatter(
    "%(asctime)s %(levelname)s [%(name)s] [%(filename)s (%(funcName)s:%(lineno)d)] - %(message)s"
)

#将格式器设置到处理器上
handler.setFormatter(formatter)

#将处理器添加到日志处理器
logger.addHandler(handler)

logger.debug("this is debug message")
logger.info("this is info message")
logger.warning("this is warning message")
logger.error("this is error message")
logger.critical("this is critical message")